package com.fj;

import java.io.Serializable;
import java.util.List;

/**
 * @author mo
 * @Description: 自定义分页对象
 * @date 2020-10-12 8:13
 */

public class Page<T> implements Serializable {

    private static final long serialVersionUID = -8555816239058085286L;
    /**
     * 当前页
     */
    private Integer pageNo = 1;
    /**
     * 总记录数 .
     */
    private Integer total;
    /**
     * 每页行数 .
     */
    private Integer pageSize = 10;
    /**
     * 页面的总数  .
     */
    private Integer pageCount;
    /**
     * 结果集中数据的起始位置  .
     */
    private Integer beginPos = 0;
    /**
     * List 集合.
     */
    private List<T> rows;

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
        //下标起始位置：(pageNo-1)*pageSize
        this.beginPos = (this.pageNo - 1) * pageSize;
    }

    /**
     * 总页面数 .
     *
     * @return Integer .
     */
    public Integer getPageCount() {
        return pageCount;
    }

    /**
     * 得到页面的当前位置 .
     *
     * @return Integer .
     */
    public Integer getBeginPos() {
        return beginPos;
    }

    public List<T> getRows() {
        return rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }

    /**
     * @param pageSize the pageSize to set
     */
    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * @param rowCount the rowCount to set
     */
    public void setRowCount(Integer rowCount) {
        this.total = rowCount;
    }

    /**
     * @param beginPos the beginPos to set
     */
    public void setBeginPos(Integer beginPos) {
        this.beginPos = beginPos;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
        //总页数=总记录数total/pageSize（+1）
        this.pageCount = (total + this.pageSize - 1) / this.pageSize;
    }

    public void setPageCount(Integer pageCount) {
        this.pageCount = pageCount;
    }

    public Integer getPageSize() {
        return pageSize;
    }
}
